package com.yunchao.feature.business.presentation.screen.details

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter4.BaseQuickAdapter
import com.yunchao.feature.base.R
import com.yunchao.feature.business.databinding.AdapterBusinessDetailsLayoutBinding
import com.yunchao.feature.business.domain.model.BusinessPackModel
import com.yunchao.library.lock.getVoucherTypeName
import com.yunchao.library.lock.getLockStatusStr

internal class BusinessDetailsAdapter : BaseQuickAdapter<BusinessPackModel, BusinessDetailsAdapter.VH>() {
    override fun onBindViewHolder(
        holder: VH,
        position: Int,
        item: BusinessPackModel?
    ) {
        holder.binding.apply {
            lockCommonCouponId.visibility =
                if (item?.voucherTypeId?.isNotBlank() == true) View.VISIBLE else View.GONE
            lockCommonCouponInfo.visibility =
                if (item?.paperTypeName?.isNotBlank() == true) View.VISIBLE else View.GONE
            lockCommonTitle.text = context.getString(R.string.锁号STR, item?.lockEPCInfo?.id)
            lockCommonCouponId.text = context.getString(R.string.券别IDSTR, item?.voucherTypeId)
            lockCommonCouponName.text =
                context.getString(R.string.券别名称STR, item?.voucherTypeName)
            lockCommonCouponInfo.text = context.getString(R.string.券别说明STR, item?.paperTypeName)
            lockCommonStatus.text =
                context.getString(R.string.锁状态STR, item?.lockEPCInfo?.getLockStatusStr())
            lockCommonNum.text =
                context.getString(R.string.张数STR, item?.lockEPCInfo?.pageNumber ?: 0)
            lockCommonMoney.text =
                context.getString(R.string.面值STR, item?.lockEPCInfo?.getVoucherTypeName())
        }
    }

    override fun onCreateViewHolder(
        context: Context,
        parent: ViewGroup,
        viewType: Int
    ): VH = VH(parent)

    internal class VH(
        parent: ViewGroup,
        val binding: AdapterBusinessDetailsLayoutBinding = AdapterBusinessDetailsLayoutBinding.inflate(
            LayoutInflater.from(parent.context),
            parent,
            false
        )
    ) : RecyclerView.ViewHolder(binding.root)

}